package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.union.cross.CrossUnionModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_QUIT, desc = "退出联盟")
public class QuitUnionCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

		ret = player.getModule(CrossUnionModule.class).canQuitUnion();

		if(ret == 0){

			player.sendPacket(Protocol.C_UNION_QUIT, UnionProto.UnionQuitReqMsg.newBuilder());
		}

	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			UnionProto.UnionQuitRespMsg.Builder respMsg = UnionProto.UnionQuitRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_UNION_QUIT, respMsg);
		}
	}

}
